package com.wzh.project.reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class TestMain {
	public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
		Class forName = Class.forName("com.wzh.project.reflect.TestClass");
		Object obj=forName.newInstance();
		Method[] methods = forName.getMethods();
		String result=null;
		for(Method m:methods) {
			try {
				if (m.getName().equals("returnString")){
					String list=(String) m.invoke(null, new Object[] {"param"});
					System.out.println(list);
					break;
				}
				if (m.getName().equals("test")){
					m.invoke(null, new Object[] {"param"});
					break;
				}
				if (m.getName().equals("testvoid")){
					m.invoke(null, new Object[] {});
					break;
				}
			} catch (Exception e) {
				System.out.println(e);
			}
		}
		for(Method m:methods) {
			try {
				if (m.getName().equals("returnString")){
					String list=(String) m.invoke(obj, new Object[] {"param"});
					System.out.println(list);
					//break;
				}
				if (m.getName().equals("test")){
					m.invoke(obj, new Object[] {"param"});
					//break;
				}
				if (m.getName().equals("testvoid")){
					m.invoke(obj, new Object[] {});
					//break;
				}
			} catch (Exception e) {
				System.out.println(e);
			}
		}
//		System.exit(0);
	}

}
